﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DGui;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace RobotGame.ScreenManagers
{
    public class frmOneView : DrawableGameComponent
    {
        DGuiManager _guiManager;
        GameOneScreen game;

        DForm _form;

        DButton buttonPlay;
        DButton buttonPause;
        DButton buttonStop;

        DText taskLabel;
        DText iconLabel;
        DText parameterLabel;
        DText variableLabel;
        DText functionLabel;
        DText userfunctionLabel;
        DText attributeLabel;
        DText controlLabel;
        DText objectLabel;

        DComboBox basicFunction;
        DComboBox userFunction;
        DComboBox attributeControl;
        DComboBox objectControl;

        DTextBox txtParameter1;
        DText par1Label;
        DTextBox txtParameter2;
        DText par2Label;

        DMultiLineTextBox task;
        DButton iconTwoView;
        private DButton iconThreeView;
        public frmOneView(GameOneScreen game)
            : base(game.ScreenManager.Game)
        {
            this.game = game;
        }
        public void LoadContent(Viewport view)
        {

            _guiManager = new DGuiManager(game.ScreenManager.Game, game.ScreenManager.SpriteBatch);

            _form = new DForm(_guiManager, "GuiTest", null);
            _form.Size = new Vector2(view.Width, view.Height);
            _form.Position = new Vector2(view.X, view.Y);
            _form.Initialize();
            _guiManager.AddControl(_form);


            // Setup sample controls in a layout
            DLayoutFlow layout = new DLayoutFlow(1,30,view.Width, view.Height, DLayoutFlow.DLayoutFlowStyle.Vertically);
            layout.Position = new Vector2(0,0);

            #region "Fucntion"
            basicFunction = new DComboBox(_guiManager);
            layout.Add(basicFunction);
            basicFunction.Position = new Vector2(565, 62);
            basicFunction.Initialize();
            basicFunction.AddItem("Test1", null);
            basicFunction.AddItem("Test2", null);
            _form.AddPanel(basicFunction);


            userFunction = new DComboBox(_guiManager);
            layout.Add(userFunction);
            userFunction.Position = new Vector2(565, 295);
            userFunction.Initialize();
            userFunction.AddItem("Test11", null);
            userFunction.AddItem("Test22", null);
            _form.AddPanel(userFunction);

            objectControl = new DComboBox(_guiManager);
            layout.Add(objectControl);
            objectControl.Position = new Vector2(320, 62);
            objectControl.Initialize();
            objectControl.AddItem("Object1", null);
            objectControl.AddItem("Object1", null);
            _form.AddPanel(objectControl);

            attributeControl = new DComboBox(_guiManager);
            layout.Add(attributeControl);
            attributeControl.Position = new Vector2(320, 295);
            attributeControl.Initialize();
            attributeControl.AddItem("Test11", null);
            attributeControl.AddItem("Test22", null);
            _form.AddPanel(attributeControl);

            #endregion

            #region "Label"
            taskLabel = new DText(_guiManager);
            taskLabel.FontName = "Miramonte";
            layout.Add(taskLabel);
            taskLabel.Text = "Task";
            taskLabel.HorizontalAlignment = DText.DHorizontalAlignment.Left;
            taskLabel.Position = new Vector2(101, 50);
            taskLabel.Initialize();
            _form.AddPanel(taskLabel);



            iconLabel = new DText(_guiManager);
            iconLabel.FontName = "Miramonte";
            layout.Add(iconLabel);
            iconLabel.Text = "Icon";
            iconLabel.HorizontalAlignment = DText.DHorizontalAlignment.Left;
            iconLabel.Position = new Vector2(840, 50);
            iconLabel.Initialize();
            _form.AddPanel(iconLabel);

            parameterLabel = new DText(_guiManager);
            parameterLabel.FontName = "Miramonte";
            layout.Add(parameterLabel);
            parameterLabel.Text = "Paramter";
            parameterLabel.HorizontalAlignment = DText.DHorizontalAlignment.Left;
            parameterLabel.Position = new Vector2(840, 280);
            parameterLabel.Initialize();
            _form.AddPanel(parameterLabel);

            variableLabel = new DText(_guiManager);
            variableLabel.FontName = "Miramonte";
            layout.Add(variableLabel);
            variableLabel.Text = "Variable";
            variableLabel.HorizontalAlignment = DText.DHorizontalAlignment.Left;
            variableLabel.Position = new Vector2(840, 540);
            variableLabel.Initialize();
            _form.AddPanel(variableLabel);


            functionLabel = new DText(_guiManager);
            functionLabel.FontName = "Miramonte";
            layout.Add(functionLabel);
            functionLabel.Text = "Basic Function";
            functionLabel.HorizontalAlignment = DText.DHorizontalAlignment.Left;
            functionLabel.Position = new Vector2(595, 50);
            functionLabel.Initialize();
            _form.AddPanel(functionLabel);

            userfunctionLabel = new DText(_guiManager);
            userfunctionLabel.FontName = "Miramonte";
            layout.Add(userfunctionLabel);
            userfunctionLabel.Text = "User Function";
            userfunctionLabel.HorizontalAlignment = DText.DHorizontalAlignment.Left;
            userfunctionLabel.Position = new Vector2(595, 280);
            userfunctionLabel.Initialize();
            _form.AddPanel(userfunctionLabel);


            objectLabel = new DText(_guiManager);
            objectLabel.FontName = "Miramonte";
            layout.Add(objectLabel);
            objectLabel.Text = "Objects";
            objectLabel.HorizontalAlignment = DText.DHorizontalAlignment.Left;
            objectLabel.Position = new Vector2(350, 50);
            objectLabel.Initialize();
            _form.AddPanel(objectLabel);

            attributeLabel = new DText(_guiManager);
            attributeLabel.FontName = "Miramonte";
            layout.Add(attributeLabel);
            attributeLabel.Text = "Attribute";
            attributeLabel.HorizontalAlignment = DText.DHorizontalAlignment.Left;
            attributeLabel.Position = new Vector2(350, 280);
            attributeLabel.Initialize();
            _form.AddPanel(attributeLabel);

            controlLabel = new DText(_guiManager);
            controlLabel.FontName = "Miramonte";
            layout.Add(controlLabel);
            controlLabel.Text = "Control";
            controlLabel.HorizontalAlignment = DText.DHorizontalAlignment.Left;
            controlLabel.Position = new Vector2(350, 540);
            controlLabel.Initialize();
            _form.AddPanel(controlLabel);

            #endregion

            #region "Button Control"
            buttonPlay = new DButton(_guiManager);
            layout.Add(buttonPlay);
            buttonPlay.Text = "Play";
            buttonPlay.Position = new Vector2(320, 565);
            buttonPlay.Initialize();
            _form.AddPanel(buttonPlay);

            buttonPause = new DButton(_guiManager);
            layout.Add(buttonPause);
            buttonPause.Text = "Pause";
            buttonPause.Position = new Vector2(320, 610);
            buttonPause.Initialize();
            _form.AddPanel(buttonPause);

            buttonStop = new DButton(_guiManager);
            layout.Add(buttonStop);
            buttonStop.Text = "Stop";
            buttonStop.Position = new Vector2(320, 655);
            buttonStop.Initialize();
            _form.AddPanel(buttonStop);
            #endregion

            #region "Textbox Parameter"
            txtParameter1 = new DTextBox(_guiManager);
            layout.Add(txtParameter1);
            txtParameter1.Position = new Vector2(805, 295);
            txtParameter1.Initialize();
            _form.AddPanel(txtParameter1);

            par1Label = new DText(_guiManager);
            par1Label.FontName = "Miramonte";
            layout.Add(par1Label);
            par1Label.Text = "X";
            par1Label.HorizontalAlignment = DText.DHorizontalAlignment.Left;
            par1Label.Position = new Vector2(785, 305);
            par1Label.Initialize();
            _form.AddPanel(par1Label);
            
            txtParameter2 = new DTextBox(_guiManager);
            layout.Add(txtParameter2);
            txtParameter2.Position = new Vector2(805, 335);
            txtParameter2.Initialize();
            _form.AddPanel(txtParameter2);

            par2Label = new DText(_guiManager);
            par2Label.FontName = "Miramonte";
            layout.Add(par2Label);
            par2Label.Text = "Y";
            par2Label.HorizontalAlignment = DText.DHorizontalAlignment.Left;
            par2Label.Position = new Vector2(785, 350);
            par2Label.Initialize();
            _form.AddPanel(par2Label);

            #endregion

            #region "Task"
            task = new DMultiLineTextBox(_guiManager);
            task.Position = new Vector2(6, 62);
            task.Size = new Vector2(244, 690);
            _form.AddPanel(task);
            #endregion

            iconTwoView = new DButton(_guiManager);
            layout.Add(iconTwoView);
            iconTwoView.FontName = "MiramonteTiny";
            iconTwoView.Text = ">>";
            iconTwoView.Position = new Vector2(970, 3);
            iconTwoView.Size = new Vector2(25, 25);
            iconTwoView.Initialize();
            _form.AddPanel(iconTwoView);
            iconTwoView.OnClick += new DButtonEventHandler(iconTwoView_OnClick);


            iconThreeView = new DButton(_guiManager);
            layout.Add(iconThreeView);
            iconThreeView.FontName = "MiramonteTiny";
            iconThreeView.Text = "<<";
            iconThreeView.Position = new Vector2(940, 3);
            iconThreeView.Size = new Vector2(25, 25);
            iconThreeView.Initialize();
            _form.AddPanel(iconThreeView);
            iconThreeView.OnClick += new DButtonEventHandler(iconThreeView_OnClick);

        }

        void iconThreeView_OnClick(GameTime gameTime)
        {
            LoadingScreen.Load(game.ScreenManager, true, new GameplayScreen());
        }

        void iconTwoView_OnClick(GameTime gameTime)
        {
            LoadingScreen.Load(game.ScreenManager, true, new GameTwoScreen());
        }


        public override void Update(GameTime gameTime)
        {
            _guiManager.Update(gameTime);

            //base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            _guiManager.Draw(gameTime);

            //base.Draw(gameTime);
        }
    }
}
